/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package JavaClass;

import java.io.File;
import java.io.IOException;
import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.xml.sax.SAXException;

/**
 *
 * @author NgocNTP60573
 */
public class SchemaValidation {
    public static boolean validateXMLSchema(String xsdFile, String xmlFile){
        try {
            SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = sf.newSchema(new File(xsdFile));
            Validator validator = schema.newValidator();
            validator.validate(new StreamSource(new File(xmlFile)));
        } catch (IOException ex) {
            System.out.println("error: " + ex.getMessage());
            return false;
        } catch (SAXException ex) {
            System.out.println("error: " + ex.getMessage());
            return false;
        }
        return true;
    }
}
